<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>5.8 π的近似值</title>
</head>

<body>
    <script>
        function pi(n) {
            var sign = 1;
            var sum = 0;
            for (var i = 1; i <= n; i++) {
                sum += sign / (2 * i - 1);
                sign *= -1;

            }
            return 4 * sum ;
        }
        console.log(pi(100));
        console.log(pi(500));
        console.log(pi(1000));
        console.log(pi(10000));
    </script>
</body>

</html>